<template>
  <el-card style="margin:20px;">
    <el-tabs v-model="activeName">
      <el-tab-pane label="用户管理" name="first">
        <el-form style="width:40%;" label-width="100px" :model="userInfo" :rules="rules">
          <el-form-item label="姓名" prop="username">
            <el-input v-model="userInfo.username" />
          </el-form-item>
          <el-form-item label="新密码" prop="password">
            <el-input v-model="userInfo.password" type="password" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="update">更新</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="配置管理" name="second">
        <UserInfo />
      </el-tab-pane>
      <el-tab-pane label="角色管理" name="third">
        <JobInfo />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import UserInfo from './components/user-info'
import JobInfo from './components/job-info'
import { getUserDetailById, saveUserDetailById } from '@/api/user'
export default {
  components: {
    UserInfo,
    JobInfo
  },
  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      activeName: 'first',
      userInfo: {
        //   专门存放基本信息
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 9, message: '密码长度6-9位', trigger: 'blur' }]
      }
    }
  },
  async created() {
    // this.$route.params.id
    const res = await getUserDetailById(this.id)
    // this.userInfo.username = res.username
    // this.userInfo.password = res.password
    this.userInfo = res
  },
  methods: {
    async update() {
      await saveUserDetailById(this.userInfo)
      this.$message.success('更新成功')
    }
  }
}
</script>

<style scoped lang='scss'></style>
